package com.rest.demo.concurrent;

/**
 * @author Administrator
 * @decription
 * @Date 2018-02-01 10:06
 */
public class ShareData implements Runnable{

    private int data = 100;

    @Override
    public void run() {
        while(data > 0) {
            synchronized (this) {
                if(data > 0) {
                    System.out.println(Thread.currentThread().getName() + ": " + data);
                    data--;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
